package com.qfedu.spring.springmvc.controller;

import com.qfedu.spring.springmvc.entity.ListUser;
import com.qfedu.spring.springmvc.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;

/**
 * @author zhang
 * @Title: commonValidateAdd
 * @date : 2022/4/29 14:29
 */
@Controller
@RequestMapping("/param")
public class ParamController {

    //前端传递数组
    // http://localhost:8080/param/array?name=张三&name=123&name=zhangsan
    @RequestMapping("/test3")
    public String test3(String[] name){
        System.out.println("name:"+ Arrays.toString(name));
        return "wecome";
    }

    //如果传递的参数是List,需要增加@RequestParam注解 ids= 1,2,3
    @RequestMapping("/test4")
    public String test4(@RequestParam List<String> ids){
        System.out.println("ids="+ ids);
        return "wecome";
    }

    //httpclient:GET http://localhost:8080/param/test5?users[0].id=3&users[0].name=zhangsan&users[0].age=12&users[0].birthday=2021-1-1
    @RequestMapping("/test5")
    public String test5(ListUser userList){
        System.out.println(userList.getUsers());
        return "wecome";
    }

    //路径传参符合restful 风格
    //httpclient:POST http://localhost:8080/param/path/555
    @RequestMapping("/path/{id}")
    public String test6(@PathVariable("id") String name){
        System.out.println("name="+name);
        return "wecome";
    }
}
